```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>全排列算法可视化解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', 'Helvetica Neue', Arial, sans-serif;
            color: #2d3748;
            background-color: #f8fafc;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background-color: #1e293b;
            border-radius: 0.75rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .fade-in {
            animation: fadeIn 0.5s ease-in-out;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .highlight {
            position: relative;
        }
        .highlight::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(167, 139, 250, 0.3);
            z-index: -1;
            transition: all 0.3s ease;
        }
        .highlight:hover::after {
            height: 100%;
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0 fade-in">
                    <h1 class="text-4xl md:text-5xl font-bold mb-4 font-serif">全排列算法解析</h1>
                    <p class="text-xl opacity-90 mb-8">探索回溯算法在排列组合问题中的精妙应用</p>
                    <div class="flex space-x-4">
                        <div class="bg-white bg-opacity-20 px-4 py-2 rounded-full flex items-center">
                            <i class="fas fa-code mr-2"></i>
                            <span>回溯算法</span>
                        </div>
                        <div class="bg-white bg-opacity-20 px-4 py-2 rounded-full flex items-center">
                            <i class="fas fa-project-diagram mr-2"></i>
                            <span>排列组合</span>
                        </div>
                    </div>
                </div>
                <div class="md:w-1/2 fade-in" style="animation-delay: 0.2s;">
                    <div class="bg-white bg-opacity-10 p-6 rounded-xl backdrop-blur-sm">
                        <div class="mermaid">
                            graph LR
                            A[开始回溯] --> B{所有元素已用?}
                            B -- 是 --> C[保存当前排列]
                            B -- 否 --> D[遍历所有元素]
                            D --> E{元素已使用?}
                            E -- 是 --> D
                            E -- 否 --> F[标记为已使用]
                            F --> G[添加到当前排列]
                            G --> H[递归调用]
                            H --> I[移除最后元素]
                            I --> J[标记为未使用]
                            J --> D
                            C --> K[返回结果]
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-6 py-16">
        <!-- Problem Section -->
        <section class="mb-20 fade-in">
            <div class="flex items-center mb-8">
                <div class="h-1 bg-purple-600 w-12 mr-4"></div>
                <h2 class="text-3xl font-bold font-serif">题目描述</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md p-8">
                <p class="text-xl mb-6 leading-relaxed">给定一个<mark class="highlight bg-yellow-100">不含重复数字</mark>的数组 <code class="bg-gray-100 px-2 py-1 rounded">nums</code>，返回其所有可能的<mark class="highlight bg-blue-100">全排列</mark>。</p>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-8 mt-8">
                    <div>
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-lightbulb text-yellow-500 mr-2"></i>
                            核心考点
                        </h3>
                        <div class="bg-indigo-50 rounded-lg p-6">
                            <div class="flex items-center mb-4">
                                <div class="bg-indigo-600 text-white p-2 rounded-full mr-3">
                                    <i class="fas fa-project-diagram"></i>
                                </div>
                                <span class="font-medium">回溯算法</span>
                            </div>
                            <p class="text-gray-700">回溯是一种通过探索所有可能的候选解来找出所有解的算法。它会逐步构建解，并在确定候选解不可行时回退。</p>
                        </div>
                    </div>
                    
                    <div>
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-chart-line text-green-500 mr-2"></i>
                            复杂度分析
                        </h3>
                        <div class="bg-green-50 rounded-lg p-6">
                            <div class="grid grid-cols-2 gap-4">
                                <div>
                                    <div class="text-sm text-gray-600">时间复杂度</div>
                                    <div class="text-2xl font-bold text-gray-800">O(n!)</div>
                                    <div class="text-sm text-gray-500">阶乘增长</div>
                                </div>
                                <div>
                                    <div class="text-sm text-gray-600">空间复杂度</div>
                                    <div class="text-2xl font-bold text-gray-800">O(n)</div>
                                    <div class="text-sm text-gray-500">递归栈深度</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Solution Section -->
        <section class="mb-20 fade-in" style="animation-delay: 0.3s;">
            <div class="flex items-center mb-8">
                <div class="h-1 bg-purple-600 w-12 mr-4"></div>
                <h2 class="text-3xl font-bold font-serif">解题思路</h2>
            </div>
            
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-12">
                <div class="bg-white rounded-xl shadow-md p-6 card-hover transition-all duration-300">
                    <div class="text-purple-600 text-2xl mb-4">
                        <i class="fas fa-1"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">回溯框架</h3>
                    <p class="text-gray-700">使用回溯法，交换数组元素生成所有排列，记录已使用的元素避免重复。</p>
                </div>
                
                <div class="bg-white rounded-xl shadow-md p-6 card-hover transition-all duration-300">
                    <div class="text-purple-600 text-2xl mb-4">
                        <i class="fas fa-2"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">递归终止</h3>
                    <p class="text-gray-700">当当前排列长度等于原数组长度时，保存该排列到结果集中。</p>
                </div>
                
                <div class="bg-white rounded-xl shadow-md p-6 card-hover transition-all duration-300">
                    <div class="text-purple-600 text-2xl mb-4">
                        <i class="fas fa-3"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">回溯操作</h3>
                    <p class="text-gray-700">在递归前后进行标记和取消标记操作，确保所有可能性被探索。</p>
                </div>
            </div>

            <div class="relative bg-white rounded-xl shadow-md overflow-hidden">
                <div class="absolute top-0 left-0 w-full h-1 bg-gradient-to-r from-purple-500 to-indigo-600"></div>
                
                <div class="p-1">
                    <div class="code-block text-gray-200 p-6 overflow-x-auto">
                        <pre><code class="language-java">public List&lt;List&lt;Integer&gt;&gt; permute(int[] nums) {
    // 结果列表，存储所有可能的排列
    List&lt;List&lt;Integer&gt;&gt; result = new ArrayList&lt;&gt;();
    
    // 当前正在构建的排列
    List&lt;Integer&gt; current = new ArrayList&lt;&gt;();
    
    // 标记数组中的哪些元素已经被使用
    boolean[] used = new boolean[nums.length];
    
    // 调用回溯方法生成排列
    backtrack(nums, used, current, result);
    
    // 返回所有排列结果
    return result;
}

/**
 * 回溯方法，用于生成全排列
 * @param nums 原始数组
 * @param used 标记元素是否已使用
 * @param current 当前正在构建的排列
 * @param result 存储所有结果的列表
 */
private void backtrack(int[] nums, boolean[] used, List&lt;Integer&gt; current, List&lt;List&lt;Integer&gt;&gt; result) {
    // 如果当前排列长度等于原始数组长度，说明找到了一个完整的排列
    if (current.size() == nums.length) {
        // 将当前排列加入结果集（需要创建一个新的列表以避免引用问题）
        result.add(new ArrayList&lt;&gt;(current));
        return;
    }
    
    // 尝试将每个未使用的元素加入到当前排列
    for (int i = 0; i &lt; nums.length; i++) {
        // 跳过已经使用过的元素
        if (used[i]) {
            continue;
        }
        
        // 标记当前元素为已使用
        used[i] = true;
        // 将当前元素加入到排列中
        current.add(nums[i]);
        
        // 递归生成剩余元素的排列
        backtrack(nums, used, current, result);
        
        // 回溯：移除最后添加的元素，将其标记为未使用
        current.remove(current.size() - 1);
        used[i] = false;
    }
}</code></pre>
                    </div>
                </div>
                
                <div class="px-6 py-4 bg-gray-50 border-t border-gray-200">
                    <div class="flex flex-wrap items-center gap-3">
                        <span class="bg-gray-200 text-gray-800 text-xs px-3 py-1 rounded-full">递归</span>
                        <span class="bg-gray-200 text-gray-800 text-xs px-3 py-1 rounded-full">回溯</span>
                        <span class="bg-gray-200 text-gray-800 text-xs px-3 py-1 rounded-full">排列组合</span>
                        <span class="bg-gray-200 text-gray-800 text-xs px-3 py-1 rounded-full">深度优先搜索</span>
                    </div>
                </div>
            </div>
        </section>

        <!-- Visualization Section -->
        <section class="fade-in" style="animation-delay: 0.4s;">
            <div class="flex items-center mb-8">
                <div class="h-1 bg-purple-600 w-12 mr-4"></div>
                <h2 class="text-3xl font-bold font-serif">算法可视化</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md p-8 mb-8">
                <div class="mermaid">
                    %%{init: {'theme': 'neutral', 'themeVariables': { 'primaryColor': '#f8fafc', 'textColor': '#2d3748' }}}%%
                    graph TD
                    A[开始] --> B[初始状态: nums=[1,2,3], used=[F,F,F], current=[]]
                    B --> C1["第一层递归: i=0, nums[0]=1"]
                    C1 --> D1["used=[T,F,F], current=[1]"]
                    D1 --> E1["第二层递归: i=1, nums[1]=2"]
                    E1 --> F1["used=[T,T,F], current=[1,2]"]
                    F1 --> G1["第三层递归: i=2, nums[2]=3"]
                    G1 --> H1["used=[T,T,T], current=[1,2,3]"]
                    H1 --> I1["保存结果 [1,2,3]"]
                    G1 --> G2["回溯: current=[1,2], used=[T,T,F]"]
                    
                    D1 --> E2["第二层递归: i=2, nums[2]=3"]
                    E2 --> F2["used=[T,F,T], current=[1,3]"]
                    F2 --> G3["第三层递归: i=1, nums[1]=2"]
                    G3 --> H2["used=[T,T,T], current=[1,3,2]"]
                    H2 --> I2["保存结果 [1,3,2]"]
                    
                    B --> C2["第一层递归: i=1, nums[1]=2"]
                    C2 --> D2["used=[F,T,F], current=[2]"]
                    D2 --> E3["第二层递归: i=0, nums[0]=1"]
                    E3 --> F3["used=[T,T,F], current=[2,1]"]
                    F3 --> G4["第三层递归: i=2, nums[2]=3"]
                    G4 --> H3["used=[T,T,T], current=[2,1,3]"]
                    H3 --> I3["保存结果 [2,1,3]"]
                    
                    D2 --> E4["第二层递归: i=2, nums[2]=3"]
                    E4 --> F4["used=[F,T,T], current=[2,3]"]
                    F4 --> G5["第三层递归: i=0, nums[0]=1"]
                    G5 --> H4["used=[T,T,T], current=[2,3,1]"]
                    H4 --> I4["保存结果 [2,3,1]"]
                    
                    B --> C3["第一层递归: i=2, nums[2]=3"]
                    C3 --> D3["used=[F,F,T], current=[3]"]
                    D3 --> E5["第二层递归: i=0, nums[0]=1"]
                    E5 --> F5["used=[T,F,T], current=[3,1]"]
                    F5 --> G6["第三层递归: i=1, nums[1]=2"]
                    G6 --> H5["used=[T,T,T], current=[3,1,2]"]
                    H5 --> I5["保存结果 [3,1,2]"]
                    
                    D3 --> E6["第二层递归: i=1, nums[1]=2"]
                    E6 --> F6["used=[F,T,T], current=[3,2]"]
                    F6 --> G7["第三层递归: i=0, nums[0]=1"]
                    G7 --> H6["used=[T,T,T], current=[3,2,1]"]
                    H6 --> I6["保存结果 [3,2,1]"]
                </div>
            </div>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div class="bg-white rounded-xl shadow-md p-6 card-hover transition-all duration-300">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-list-ol text-purple-600 mr-2"></i>
                        示例排列过程
                    </h3>
                    <div class="space-y-3">
                        <div class="flex items-center">
                            <div class="bg-gray-100 rounded-full w-8 h-8 flex items-center justify-center mr-3">1</div>
                            <div class="flex space-x-1">
                                <div class="bg-purple-100 text-purple-800 rounded px-2 py-1">1</div>
                                <div class="bg-purple-100 text-purple-800 rounded px-2 py-1">2</div>
                                <div class="bg-purple-100 text-purple-800 rounded px-2 py-1">3</div>
                            </div>
                        </div>
                        <div class="flex items-center">
                            <div class="bg-gray-100 rounded-full w-8 h-8 flex items-center justify-center mr-3">2</div>
                            <div class="flex space-x-1">
                                <div class="bg-purple-100 text-purple-800 rounded px-2 py-1">1</div>
                                <div class="bg-purple-100 text-purple-800 rounded px-2 py-1">3</div>
                                <div class="bg-purple-100 text-purple-800 rounded px-2 py-1">2</div>
                            </div>
                        </div>
                        <div class="flex items-center">
                            <div class="bg-gray-100 rounded-full w-8 h-8 flex items-center justify-center mr-3">3</div>
                            <div class="flex space-x-1">
                                <div class="bg-purple-100 text-purple-800 rounded px-2 py-1">2</div>
                                <div class="bg-purple-100 text-purple-800 rounded px-2 py-1">1</div>
                                <div class="bg-purple-100 text-purple-800 rounded px-2 py-1">3</div>
                            </div>
                        </div>
                        <div class="flex items-center">
                            <div class="bg-gray-100 rounded-full w-8 h-8 flex items-center justify-center mr-3">4</div>
                            <div class="flex space-x-1">
                                <div class="bg-purple-100 text-purple-800 rounded px-2 py-1">2</div>
                                <div class="bg-purple-100 text-purple-800 rounded px-2 py-1">3</div>
                                <div class="bg-purple-100 text-purple-800 rounded px-2 py-1">1</div>
                            </div>
                        </div>
                        <div class="flex items-center">
                            <div class="bg-gray-100 rounded-full w-8 h-8 flex items-center justify-center mr-3">5</div>
                            <div class="flex space-x-1">
                                <div class="bg-purple-100 text-purple-800 rounded px-2 py-1">3</div>
                                <div class="bg-purple-100 text-purple-800 rounded px-2 py-1">1</div>
                                <div class="bg-purple-100 text-purple-800 rounded px-2 py-1">2</div>
                            </div>
                        </div>
                        <div class="flex items-center">
                            <div class="bg-gray-100 rounded-full w-8 h-8 flex items-center justify-center mr-3">6</div>
                            <div class="flex space-x-1">
                                <div class="bg-purple-100 text-purple-800 rounded px-2 py-1">3</div>
                                <div class="bg-purple-100 text-purple-800 rounded px-2 py-1">2</div>
                                <div class="bg-purple-100 text-purple-800 rounded px-2 py-1">1</div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md p-6 card-hover transition-all duration-300">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-question-circle text-indigo-600 mr-2"></i>
                        常见问题解答
                    </h3>
                    <div class="space-y-4">
                        <div>
                            <h4 class="font-medium text-gray-800">为什么需要创建新的ArrayList保存结果？</h4>
                            <p class="text-gray-600 text-sm">因为Java中的List是引用类型，直接添加current会导致所有结果都指向同一个列表。创建新列表可以保存当前状态的独立副本。</p>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-800">如何优化空间复杂度？</h4>
                            <p class="text-gray-600 text-sm">可以通过原地交换数组元素的方式实现，省去used数组和current列表的空间开销，空间复杂度可降至O(1)。</p>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-800">如何处理包含重复元素的情况？</h4>
                            <p class="text-gray-600 text-sm">需要先排序数组，然后在回溯时跳过与前一个元素相同且未被使用的元素，避免生成重复排列。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            securityLevel: 'loose'
        });
        
        // 微交互效果
        document.addEventListener('DOMContentLoaded', function() {
            const highlights = document.querySelectorAll('.highlight');
            highlights.forEach(highlight => {
                highlight.addEventListener('mouseenter', function() {
                    this.classList.add('transition-all', 'duration-300');
                });
            });
            
            const cards = document.querySelectorAll('.card-hover');
            cards.forEach(card => {
                card.addEventListener('mouseenter', function() {
                    this.classList.add('shadow-lg');
                });
                card.addEventListener('mouseleave', function() {
                    this.classList.remove('shadow-lg');
                });
            });
        });
    </script>
</body>
</html>
```